User Function M030Inc
Local cQuery   := ''
Local cTexto    := ''
Local nProx    := 1
local aArea    := GetArea()        

                     
cTexto := '************************'+CHR(13)+ chr(10)
cTexto += 'Cod :'+SA1->A1_COD+ CHR(13)+ chr(10)
cTexto += 'FUNCAO :'+Alltrim(FunName())+ CHR(13)+ chr(10)
cTexto += '************************'+CHR(13)+ chr(10)
cTexto += IIF(l030Auto,'Auto=SIM','Auto=NAO') +CHR(13)+ chr(10)
cTexto += IIF(INCLUI,'I=SIM','I=NAO') +CHR(13)+ chr(10)


If PARAMIXB <> 3
	IF l030Auto
		IF INCLUI
			IF !(SUBSTR(SA1->A1_COD,1,1) $  'LEAIN' )
				If Select("NUM_PRX") > 0
					NUM_PRX->(dbCloseArea())
				EndIf
				cQuery    =  " SELECT Max(CASE WHEN SUBSTRING(A1_COD,1,1)='L'
				cQuery    += "            THEN SUBSTRING(A1_COD,2,5)  "
				cQuery    += "            ELSE  ''       "
				cQuery    += "            END)   MAXNUM  "
				cQuery    += " FROM "+RetSqlName("SA1")
				cQuery := ChangeQuery(cQuery)
				dbUseArea(.T.,"TOPCONN",TcGenQry(,,cQuery),"NUM_PRX",.T.,.F.)
				dbSelectArea("NUM_PRX")
				
				NUM_PRX->(dbGoTop())
				RecLock("SA1", .F.)
				IF NUM_PRX->(Eof())
					SA1->A1_COD:= 'L00001'
				ELSE
					SA1->A1_COD:= 'L'+STRZERO(Val(NUM_PRX->MAXNUM)+1,5)
				ENDIF
				SA1->(msUnlock())
				cTexto += 'Cod :'+SA1->A1_COD+ CHR(13)+ chr(10)
			ENDIF
		ENDIF
	ENDIF
	
	memowrite('cli_logix.txt',cTexto)
	
EndIf

RestArea(aArea)

Return